package deatax;

import deatax.display.Texture;
import java.awt.Image;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author pson
 */
public class Dice {

    ArrayList<Die> pool;
    int[] current;
    private static Image texture_white = null;
//    private static Image texture_black = null;

    /**
     * Creates a new set of dice with no die in the pool
     */
    public Dice() {
        pool = new ArrayList<Die>();
    }

    public static Image getTexture() {
        if (texture_white == null) {
            texture_white = Texture.loadImage("tiles/dice_white.png");
        }
        return texture_white;
//        if (texture_black == null) {
//            texture_black = Texture.loadImage("tiles/dice_black.png");
//        }
    }

    /**
     * Creates a new set of dice with [num] die of [sided] sides each
     * @param num Number of die to add to the pool
     * @param sided Number of sides of each die
     */
    public Dice(int num, int sided) {
        this();
        for (int i = 0; i < num; i++) {
            pool.add(new Die(sided));
        }

        current = new int[pool.size()];
    }

    public ArrayList<Die> getPool() {
        return pool;
    }

    public int[] current() {
        return current;
    }

    public void newRoll() {
        int i = 0;
        for (Die die : pool) {
            die.newRoll();
            current[i++] = die.current();
        }
    }

    public int roll() {
        int sum = 0;
        int i = 0;
        for (Die die : pool) {
            sum += die.roll();
            current[i++] = die.current();
        }
        return sum;
    }
}
